package com.cc.wechat.controller;

import com.cc.wechat.common.ApiResponse;
import com.cc.wechat.common.constants.MessageConstants;
import com.cc.wechat.dto.response.FileUploadResponse;
import com.cc.wechat.service.FileService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/api/files")
@RequiredArgsConstructor
public class FileController {

    private final FileService fileService;

    /**
     * 文件上传
     *
     * @param file 文件
     * @param type 文件类型（avatar/image等）
     * @return 文件上传响应
     */
    @PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public ApiResponse<FileUploadResponse> uploadFile(
            @RequestParam("file") MultipartFile file,
            @RequestParam("type") String type) {
        return ApiResponse.success(MessageConstants.File.UPLOAD_SUCCESS, fileService.uploadFile(file, type));
    }

    /**
     * 删除文件
     *
     * @param objectName 对象名称
     * @return 响应结果
     */
    @DeleteMapping("/{objectName}")
    public ApiResponse<Void> deleteFile(@PathVariable String objectName) {
        fileService.deleteFile(objectName);
        return ApiResponse.success(MessageConstants.File.DELETE_SUCCESS,null);
    }
} 